home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / eignval < prev    next >
Text File  |  1995-03-31  |  5KB  |  169 lines

  1. Article 3024 of comp.sys.handhelds:
  2. Path: en.ecn.purdue.edu!noose.ecn.purdue.edu!samsung!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!orstcs!usenet!jacobsd
  3. From: jacobsd@usenet@scion.CS.ORST.EDU (Dana Jacobsen)
  4. Newsgroups: comp.sys.handhelds
  5. Subject: Re: Eigenvalues
  6. Message-ID: <1990Dec22.002458.26290@usenet@scion.CS.ORST.EDU>
  7. Date: 22 Dec 90 00:24:58 GMT
  8. References: <9012201714.AA26392@CS.ORST.EDU>
  9. Organization: Oregon State University, Computer Science Dept
  10. Lines: 155
  11.  
  12. In <9012201714.AA26392@CS.ORST.EDU> john%solvint@orstcs.UUCP writes:
  13.  
  14. >> Someone posted a message containing the program
  15. >> \<<A I L * - DET \>> (where I = Identity matrix)
  16. >> for finding the characteristic polynomial of a matrrix A.
  17. >> I can't make it work because the 48 doesn't seem to permit
  18. >> symbolic entries in arrayse, as was also the case with the 28s
  19. >> Can someone give me the reference to this message?
  20. >> Thanks...jim_wendel@ub.cc.umich.edu or jwendel@isdmnl.wr.usgs.gov
  21. >> 
  22. >> 
  23.  
  24. >Symbollic entries in arrays is not the point.
  25.  
  26. >One uses this program by making it the current SOLVER equation, putting a square
  27. >array in 'A', the square identity in 'I' and solving for 'L', the eigenvalue.
  28. >This program looks like it was taken from the "Easy Course in Using the HP-28S"
  29. >where it was used to solve for the eigenvalues of matrix 'A', but since the 28
  30. >doesn't have the lambda character, L was used instead.
  31.  
  32.   The HP-28 solution book "Matrices & Vectors" has a more elegant solution that
  33. is probably faster and works better in that you don't have to call the solver.
  34. I wrote a plug-and-chug program around this.  Enter the matrix, press the key,
  35. and you get back the eigenvalues.
  36.   It works by finding the characteristic polynomial, then solving for that.
  37. I posted this a while ago, but some peopl seem to have missed it, and I also 
  38. left out the root-finding programs.  This program needs some way of solving an
  39. arbitrary degree polynomial.  The program "BAIRS" which came by the net a
  40. while back seems to do the job well.  I don't remember who wrote this though
  41. (Wayne Scott?).   
  42.   All the programs are available via anonymous FTP from scion.cs.orst.edu
  43. (128.193.32.25):~ftp/pub/jacobsd/{hp.eig,hp.proot}.
  44.  
  45. %%HP: T(3)A(R)F(.);
  46.       EIGVAL
  47.         \<< DUP DUP
  48. SIZE 1 GET \-> t g n
  49.           \<< { } 1 n
  50.             START 0
  51. 1 n
  52.               FOR i
  53. t i DUP 2 \->LIST GET
  54. +
  55.               NEXT
  56. 1 \->LIST + 't' g
  57. STO*
  58.             NEXT \->
  59. b
  60.             \<< { 1 }
  61. 1 n
  62.               FOR i
  63. \-> s
  64. \<< 0 1 i
  65.   FOR j b j GET s i
  66. j - 1 + GET * -
  67.   NEXT i / 1 \->LIST
  68. s SWAP +
  69. \>>
  70.               NEXT
  71.             \>>
  72.           \>> PROOT
  73.         \>>
  74.  
  75.   This is my eigenvalue program.  PROOT is a program that will solve f(x)=0
  76. for a polynomial.  It takes a list of numbers which are coefficients for the
  77. polynomial (i.e. "4 * x^2 + 3 * x - 3" would be { 4 3 -2 } ).  Programs for
  78. this are available on the net, or I could send mine to you.  (Or you can
  79. anonymous ftp it from scion.cs.orst.edu:pub/jacobsd/proot & math)  The 
  80. files aren't in great shape (^M's at the end of each line) but it's there.
  81.  
  82.     Start:     An n x n matrix in level 1
  83.     Stop:      n real or complex values on the stack.  These are the 
  84.            eigenvalues.
  85.  
  86. %%HP: T(3)A(R)F(.);
  87. PROOT
  88. \<< DUP SIZE \-> n
  89.   \<<
  90.     IF n 3 >
  91.     THEN DUP { HOME
  92. MATH POLY BAIRS }
  93. RCL EVAL SWAP OVER
  94. { HOME MATH POLY
  95. PDIV } RCL EVAL
  96. DROP2 \-> a b
  97.       \<< a PROOT b
  98. PROOT
  99.       \>>
  100.     ELSE
  101.       IF n 2 >
  102.       THEN { HOME
  103. MATH POLY QUD } RCL
  104. EVAL
  105.       ELSE LIST\->
  106. DROP NEG SWAP /
  107.       END
  108.     END
  109.   \>>
  110. \>>
  111.  
  112. BAIRS
  113. \<< LIST\-> 1 1
  114. \-> n R S
  115.   \<<
  116.     DO 0 n
  117. 1 + PICK 0 0 0 4
  118. PICK 5 n + 7
  119.     FOR J
  120. J PICK R 7 PICK * +
  121. S 8 PICK * + 7 ROLL
  122. DROP DUP 6 ROLLD R
  123. 3 PICK * + S 4 PICK
  124. * + 5 ROLL DROP -1
  125.     STEP
  126. 3 PICK SQ 3 PICK 6
  127. PICK * -
  128.       IF
  129. DUP 0 ==
  130.       THEN
  131. DROP 1 1
  132.       ELSE
  133. 6 PICK 6 PICK * 5
  134. PICK 9 PICK * -
  135. OVER / 4 PICK 9
  136. PICK * 8 PICK 7
  137. PICK * - ROT /
  138.       END
  139. DUP 'S' STO+ SWAP
  140. DUP 'R' STO+
  141.     UNTIL
  142. R\->C ABS .000000001
  143. < 7 ROLLD 6 DROPN
  144.     END n
  145. DROPN 1 R NEG S NEG
  146. 3 \->LIST
  147.   \>>
  148. \>>
  149.  
  150. QUD
  151. \<< LIST\->
  152. \->ARRY DUP 1 GET /
  153. ARRY\-> DROP ROT DROP
  154. SWAP 2 / NEG DUP SQ
  155. ROT - \v/ DUP2 + 3
  156. ROLLD -
  157. \>>
  158.  
  159.  
  160.   That's it.  Hope everything works fine -- I don't have a cable to transfer
  161. the stuff, so got a friend to do the transfer..
  162. --
  163. Dana Jacobsen                       Oregon State University
  164. jacobsd@cs.orst.edu                   Computer Science
  165. ..!hplabs!hp-pcd!orstcs!jacobsd
  166. Dana_Jacobsen@RPITSMTS.BITNET            `Once a daemon, always a daemon'
  167.  
  168.  
  169.